import time
import random


def start(user, task={}):
    music = user.music

    if len(task['songId']) == 0:
        user.taskInfo(task['taskName'], '请填写歌曲id')
        return
    song_id = random.choice(task['songId'])
    if len(task['msg']) > 0:
        event_msg = random.choice(task['msg'])
    else:
        event_msg = '每日分享'

    result = music.share_resource(type='song', msg=event_msg, id=song_id)
    if result['code'] == 200:
        event_id = result['id']
        if task['delete']:
            time.sleep(0.5)
            delete_result = music.event_delete(event_id)
            user.taskInfo(task['taskName'], '动态分享歌曲成功，已删除动态')
        else:
            user.taskInfo(task['taskName'], '动态分享歌曲成功')
    else:
        user.taskInfo(task['taskName'], user.errMsg(result))
